package com.burgeon.backend.SHOP.controller;


import com.burgeon.backend.SHOP.service.AppActivityService;
import com.burgeon.backend.SHOPBACKEND.entity.SevenDaysReturn;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.HashMap;


@RestController
@RequestMapping("appactivity")
public class AppActivityController extends BaseController {
    @Autowired
    private AppActivityService appActivityService;

    @RequestMapping("sevenDaysReturnData")
    public ResponseResult<SevenDaysReturn> sevenDaysReturnData(HttpSession session) {
        String token = session.getAttribute("token").toString();
        SevenDaysReturn data = appActivityService.sevenDaysReturnData(token);
        return new ResponseResult<SevenDaysReturn>(SUCCESS,data);
    }

    @RequestMapping("seckillMail")
    public ResponseResult<HashMap> getMailActivityBySeckill(String sid,HttpSession session) {
        System.err.println(sid);
        String token = session.getAttribute("token").toString();
        String phone = session.getAttribute("phone").toString();
        HashMap data = appActivityService.getMailActivityBySeckill(sid, phone, token);

        return new ResponseResult<HashMap>(SUCCESS,data);
    }

    @RequestMapping("mail")
    public ResponseResult<HashMap> getMailActivity(String[] gids,HttpSession session) {
        System.err.println(Arrays.toString(gids));
        String token = session.getAttribute("token").toString();
        String phone = session.getAttribute("phone").toString();
        HashMap data = appActivityService.getMailActvity(gids, phone, token);

        return new ResponseResult<HashMap>(SUCCESS,data);
    }



    @RequestMapping("calculate")
    public ResponseResult<HashMap> GetRetailRecord(HttpSession session) {
        String token = session.getAttribute("token").toString();
        String uid = session.getAttribute("uid").toString();
        String discount;
        if (null != session.getAttribute("user_discount")) {
            discount = session.getAttribute("user_discount").toString();
        }else {
            discount = "1";
        }
        String isPlus;  //是plus session会赋值Y  不是为null
        if (null!=session.getAttribute("user_is_plus")){
            isPlus = session.getAttribute("user_is_plus").toString();
        }else {
            isPlus = "N";
        }
        HashMap data = appActivityService.calculateOrderPrice(uid, token,discount,isPlus);

        return new ResponseResult<HashMap>(SUCCESS,data);
    }


}
